package com.example.tnot.Teacher.CoursePart.adapter;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.RecyclerView;

import com.example.tnot.R;
import com.example.tnot.Util.ToastUtil;

import java.util.List;

public class rv_ClassAdapter extends RecyclerView.Adapter<rv_ClassAdapter.ViewHolder>{

    private List<String> classes;

    public rv_ClassAdapter(List<String> classes) {
        this.classes = classes;
    }


    @NonNull
    @Override
    public rv_ClassAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.item_rv_teacher_teach_course_internal_class, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull rv_ClassAdapter.ViewHolder holder, @SuppressLint("RecyclerView") int position) {
        holder.tv_ClassName.setText(classes.get(position));
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("className",classes.get(position));
                bundle.putString("jumpType","教学");
                NavController navController = Navigation.findNavController(v);
                navController.navigate(R.id.action_courseContainerFragment_to_classDetailFragment, bundle);
            }
        });
    }

    @Override
    public int getItemCount() {
        return classes.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        public TextView tv_ClassName;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_ClassName = itemView.findViewById(R.id.tv_ClassName);
        }
    }
}
